00001 /* 00002 * Copyright (c) 2013 Battelle Memorial Institute 00003 * Licensed under modified BSD License. A copy of this license can be found 00004 * in the LICENSE file in the top level directory of this distribution. 00005 */ 00006 // ------------------------------------------------------------- 00007 /** 00008 * @file ds_app_module.hpp 00009 * @author Shuangshuang Jin 00010 * @date September 19, 2013 00011 * 00012 * @brief 00013 * 00014 * 00015 */ 00016 // ------------------------------------------------------------- 00017 00018 #ifndef _ds_app_module_h_ 00019 #define _ds_app_module_h_ 00020 00021 #include "boost/smart_ptr/shared_ptr.hpp" 00022 #include "gridpack/serial_io/serial_io.hpp" 00023 #include "ds_factory_module.hpp" 00024 00025 namespace gridpack { 00026 namespace dynamic_simulation_r { 00027 00028 // Calling program for dynamic simulation application 00029 00030 class DSAppModule 00031 { 00032 public: 00033 /** 00034 * Basic constructor 00035 */ 00036 DSAppModule(void); 00037 00038 /** 00039 * Basic destructor 00040 */ 00041 ~DSAppModule(void); 00042 00043 /** 00044 * Read in and partition the powerflow network. The input file is read 00045 * directly from the Dynamic_simulation block in the configuration file so no 00046 * external file names or parameters need to be passed to this routine 00047 * @param network pointer to a DSNetwork object. This should not have any 00048 * buses or branches defined on it. 00049 * @param config pointer to open configuration file 00050 */ 00051 void readNetwork(boost::shared_ptr<DSNetwork> &network, 00052 gridpack::utility::Configuration *config); 00053 00054 /** 00055 * Assume that DSNetwork already exists and just cache an internal pointer 00056 * to it. This routine does not call the partition function. Also read in 00057 * simulation parameters from configuration file 00058 * @param network pointer to a complete DSNetwork object. 00059 * @param config pointer to open configuration file 00060 */ 00061 void setNetwork(boost::shared_ptr<DSNetwork> &network, 00062 gridpack::utility::Configuration *config); 00063 00064 /** 00065 * Read generator parameters. These will come from a separate file (most 00066 * likely). The name of this file comes from the input configuration file. 00067 */ 00068 void readGenerators(void); 00069 00070 /** 00071 * Set up exchange buffers and other internal parameters and initialize 00072 * network components using data from data collection 00073 */ 00074 void initialize(); 00075 00076 /** 00077 * Execute the time integration portion of the application 00078 */ 00079 void solve(gridpack::dynamic_simulation_r::DSBranch::Event fault); 00080 00081 /** 00082 * Write out final results of dynamic simulation calculation to standard output 00083 */ 00084 void write(); 00085 00086 /** 00087 * Read faults from external file and form a list of faults 00088 * @param cursor pointer to open file contain fault or faults 00089 * @return a list of fault events 00090 */ 00091 std::vector<gridpack::dynamic_simulation_r::DSBranch::Event> 00092 getFaults(gridpack::utility::Configuration::CursorPtr cursor); 00093 00094 /** 00095 * Read in generators that should be monitored during simulation 00096 */ 00097 void setGeneratorWatch(); 00098 00099 private: 00100 00101 /** 00102 * Utility function to convert faults that are in event list into 00103 * internal data structure that can be used by code 00104 */ 00105 void setFaultEvents(); 00106 00107 /** 00108 * Open file (specified in input deck) to write generator results to. 00109 * Rotor angle and speeds from generators specified in input deck will be 00110 * written to this file at specified time intervals 00111 */ 00112 void openGeneratorWatchFile(); 00113 00114 /** 00115 * Close file contain generator watch results 00116 */ 00117 void closeGeneratorWatchFile(); 00118 00119 std::vector<gridpack::dynamic_simulation_r::DSBranch::Event> p_faults; 00120 00121 // pointer to network 00122 boost::shared_ptr<DSNetwork> p_network; 00123 00124 // communicator for network 00125 gridpack::parallel::Communicator p_comm; 00126 00127 // pointer to factory 00128 boost::shared_ptr<DSFactoryModule> p_factory; 00129 00130 // Simulation time 00131 double p_sim_time; 00132 00133 // Time step 00134 double p_time_step; 00135 00136 // Current step count? 00137 int p_S_Steps; 00138 00139 // pointer to bus IO module 00140 boost::shared_ptr<gridpack::serial_io::SerialBusIO<DSNetwork> > 00141 p_busIO; 00142 00143 // pointer to branch IO module 00144 boost::shared_ptr<gridpack::serial_io::SerialBranchIO<DSNetwork> > 00145 p_branchIO; 00146 00147 // pointer to configuration module 00148 gridpack::utility::Configuration *p_config; 00149 00150 // Flag indicating that generators are to be monitored 00151 bool p_generatorWatch; 00152 00153 // Frequency to write out generator watch results 00154 int p_watchFrequency; 00155 00156 // bus indices of generators that are being monitored 00157 std::vector<int> p_gen_buses; 00158 00159 // tags of generators that are being monitored 00160 std::vector<std::string> p_tags; 00161 00162 // pointer to bus IO module that is used for generator results 00163 boost::shared_ptr<gridpack::serial_io::SerialBusIO<DSNetwork> > 00164 p_generatorIO; 00165 }; 00166 00167 } // dynamic simulation 00168 } // gridpack 00169 #endif